/*
 * What is an Effect?
 * Effects are graphical objects that do not affect gameplay, yet
 * convey important visual information to the player. Effects include
 * weapon animations and hit animations.
 * If the effect is animated, the animation must consist of images
 * of equal size which are placed from left to right in the source
 * bitmap.
 * An effect is drawn centered on the specified tile coordinates, even
 * if the effect bitmap is larger than TILE_SIZE*TILE_SIZE.
 * Effects are mostly drawn to the screen after map tiles, players and
 * map overlay decorations, but before projectiles.
 * A set of effects is maintained by the MapDisplay object.
 */

#ifndef EFFECT_H_
#define EFFECT_H_

#include <allegro.h>
#include "anim.h"
#include "util/rect.h"
#include "util/direction.h"

#define EFFECT_TEXTLEN 100
#define EFFECT_COOLDOWN_ATTACK (assert(FPS/10>0),3*(FPS/10))
#define EFFECT_COOLDOWN_DAMAGE (1.5*FPS)
#define EFFECT_COOLDOWN_GOLD (1.5*FPS)

typedef struct {
	enum { EFFECT_BITMAP, EFFECT_STRIKE, EFFECT_TEXT } type;
	
	union {
		struct {
			FONT* font;
			char string [EFFECT_TEXTLEN];
		} text;
		struct {
			BITMAP* source;
			
			// location of bmp portion in source bitmap in px
			int left;
			int top;
			int width;
			int height;
			
			// for anims
			int frame_w; // advance in px between frames
			Anim anim;
		} bitmap;
	};
	
	// If EFFECT_DMGTEXT, the effect is a damage text string and uses the following:
	
	Coord coord; // tile coordinates where effect is visible
	Coord origin; // tile coords which dictate lighting, 'center' of effect
	int offset_x; // pixel coords added to tile coords
	int offset_y;
	int cooldown;
	
	Direction dir; // only for EFFECT_STRIKE
} Effect;

/*
 * Constructor for weapon strike effect
 * sheet contains weapon strike animations for one specific weapon in
 * every direction. dir is the direction of the blow, where is the
 * location in tile coordinates of the actor who caused the strike.
 */
void effect_init_weapon (Effect* effect, BITMAP* sheet, Direction dir, Coord where);

/*
 * Constructor for damage number effect
 * amount is the number of hit points of damage caused. where is the
 * location in tile coordinates of the actor who suffered the damage.
 */
void effect_init_damage (Effect* effect, int amount, Coord where);

/*
 * Constructor for gold number effect
 * amount is the number of gold points collected. where is the
 * location in tile coordinates of the treasure chest.
 */
void effect_init_gold (Effect* effect, int amount, Coord where);

/*
 * Causes the effect to advance by one game tick.
 * e.g. some effects change their drawing offset
 */
void effect_update (Effect* effect);

/*
 * Draws the background portion of the effect. Since effects are in
 * foreground by default, this is only relevant if the effect's
 * is_background flag is set, and then it only applies to the portion
 * of the effect's graphics which overlaps with the effect's defined
 * background_area.
 */
void effect_draw_bg (Effect* effect, BITMAP* target, 
                     int xoffset, int yoffset, int darkness);

/*
 * Draws the foreground portion of the effect.
 * target is the viewport buffer. xoffset and yoffset are the scroll
 * offsets of the map on the screen. darkness is a value describing the
 * visibility of the effect from an observer's point of view. It is
 * passed to dark_blit and may cause the effect to appear invisible.
 */
void effect_draw_fg (Effect* effect, BITMAP* target, 
                     int xoffset, int yoffset, int darkness);

#endif // __EFFECT_H
